/*
 * Famon (http://code.google.com/p/famon/)
 * Copyright (c) 2010 Carl Crous.
 *
 * This file is part of Famon.
 *
 * Famon is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Famon is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Famon.  If not, see <http://www.gnu.org/licenses/>.
 */

package za.org.foobar.famon.frontend.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import org.gwtportlets.portlet.client.WidgetFactory;
import za.org.foobar.famon.frontend.client.dto.ApplicationDto;
import za.org.foobar.famon.frontend.client.dto.CModelObjectSuggestion;

/**
 * Our service interface.
 */
@RemoteServiceRelativePath("FamonService")
public interface FamonService extends RemoteService {

    public static class App {
        private static FamonServiceAsync ourInstance = null;

        public static synchronized FamonServiceAsync get() {
            if (ourInstance == null) {
                ourInstance = (FamonServiceAsync)GWT.create(FamonService.class);
            }
            return ourInstance;
        }
    }

    public static final String TOKEN_FAILURE_BROWSER = "failures";
    public static final String ARG_APPLICATION = "application";
    public static final String ARG_VERSION = "version";
    public static final String ARG_INSTANCE = "instance";

    /**
     * Load the root layout for our application and the page for the
     * history token.
     */
    public FamonPage getRootPage(String historyToken);

    /**
     * Load a page for the history token.
     */
    public FamonPage getPage(String historyToken);

    /**
     * Update the page layout.
     */
    public void savePage(String pageName, WidgetFactory wf);

    /**
     * Refresh the factory with new data from the server.
     */
    public WidgetFactory refresh(String historyToken, WidgetFactory wf);


    public void newPage(String page) throws FamonException;

    public String getPageXml(String page) throws FamonException;

    public void setPageXml(String page, String value) throws FamonException;

    public CModelObjectSuggestion[] getModelObjects(
            String dbClassName, String dbValueField, String dbWhere,
            String query) throws FamonException;

    public void updateApplication(ApplicationDto application) throws FamonException;

    public void deleteApplication(String applicationId) throws FamonException;
}
